package jp.co.cos.ittrick.channel.controller.admin;

import jp.co.cos.ittrick.channel.model.PreModel;
import jp.co.cos.ittrick.channel.service.PreService;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class PreDownloadFlgController extends Controller {

    private PreService preService;

    public PreDownloadFlgController() {
        preService = new PreService();
    }

    @Override
    public Navigation run() throws Exception {

        // リクエストパラメータ
        String channel = asString("channel");
        String chapter = asString("chapter");
        String page = asString("page");
        String pre = asString("pre");

        PreModel preModel = preService.getPreByKey(Integer.valueOf(pre));
        if(preModel.getDownloadFlg()) {
            preModel.setDownloadFlg(false);
        }else {
            preModel.setDownloadFlg(true);
        }

        preService.update(preModel);

        return redirect("/admin/pageEdit?channel=" + channel + "&chapter=" + chapter + "&page=" + page + "&pre=" + pre);
    }
}
